#ifndef _CHP_COMDEF_HEAD
#define _CHP_COMDEF_HEAD

/* 
* Compile Switch Micro 
* it use prefix "CHP_SWITCH_"
*/
#define CHP_SWITCH_PLAY_FROM_HOST_EN	// Enable play from host function.
//#define CHP_SWITCH_8BIT_IOU			// IOU 8Bit data bus, default 16bit
//#define CHP_SWITCH_PLATFORM_16BIT		// use 16bit platform
//#define CHP_SWITCH_LOW_POWER			// Low power mode


#ifndef NULL
#define NULL 0
#endif
/* Data Type */
#define CHP_WCHAR	unsigned short
#define CHP_U8		unsigned char
#define CHP_U16		unsigned short
#define CHP_U32		unsigned int
#define CHP_FAR		

#define CHP_8		char
#define CHP_16		short
#define CHP_32		int


#define CHP_INB(io)        (*((volatile CHP_U8 *) (io)))
#define CHP_INH(io)       (*((volatile CHP_U16 *) (io)))
#define CHP_INW(io)       (*((volatile CHP_U32 *) (io)))

#define CHP_OUTB(io, val)  (*((volatile CHP_U8 *) (io)) = ((CHP_U8) (val)))
#define CHP_OUTH(io, val) (*((volatile CHP_U16 *) (io)) = ((CHP_U16) (val)))
#define CHP_OUTW(io, val) (*((volatile CHP_U32 *) (io)) = ((CHP_U32) (val)))



#define CHP_INBM( io, msk ) ( CHP_INB( io ) & (msk) )
#define CHP_INHM( io, msk ) ( CHP_INH( io ) & (msk) )
#define CHP_INWM( io, msk ) ( CHP_INW( io ) & (msk) )

#define CHP_OUTBM( io, msk, val ) \
{\
  CHP_U8 tmp;\
  (tmp) =(((CHP_INB(io) & (CHP_U8)(~(msk))) | ((CHP_U8)((val) & (msk)))));\
  ((void) CHP_OUTB( io, (CHP_U8)(tmp)));\
}\
  
  
#define CHP_OUTHM( io, msk, val) \
  {\
  CHP_U16 tmp;\
  (tmp) =(((CHP_INH(io) & (CHP_U16)(~(msk))) |((CHP_U16)((val) & (msk)))));\
  (void) CHP_OUTH( io, (CHP_U16)(tmp));\
  }\

#define CHP_OUTWM( io, msk, val) \
  {\
  CHP_U32 tmp;\
  (tmp) =(((CHP_INW(io) & (CHP_U32)(~(msk))) |((CHP_U32)((val) & (msk)))));\
  (void) CHP_OUTW( io, (CHP_U32)(tmp));\
  }\


#define CHP_IF_ERROR_RTN(rtn)	{if(rtn){return rtn;}}
#define CHP_IF_ERROR_GOTO(rtn, ext_flg)	{if(rtn){goto ext_flg;}}

#define WORD_TO_DWORD(L,H)  (L|(H<<16))  
#define GET_WORDL(length)       ((CHP_U16)length)               
#define GET_WORDH(length)       ((CHP_U16)(length>>16))               


#endif /*_CHP_COMDEF_HEAD*/

